import api from './api.js'  
 
// 登录状态
const loginState = async function(type){	 
	let uid = uni.getStorageSync('userInfo').id;
	let isLogin=''; 
	 
	if(type&&type=='reset'){ 
		if(!uid){
			uni.showToast({
				icon:'loading',
				title:'请先登录...',
				mask:true,
				duration:1000
			})
			uni.removeStorageSync('userInfo');
			uni.removeStorageSync('cookieKey');
			setTimeout(()=>{
				uni.navigateTo({
					url:'/pages/login/login?backType=prev'
				})
			},1000)
		}else{ 
			let res=await api.user_api.checkLogin(); 
			if(res.data.ret!=0){ 				 
				uni.showToast({
					icon:'loading',
					title:'登录已超时...',
					mask:true,
					duration:1000
				})
				uni.removeStorageSync('userInfo'); 
				uni.removeStorageSync('cookieKey');
				
				setTimeout(()=>{
					uni.navigateTo({
						url:'/pages/login/login?backType=prev'
					})
				},1000)
				isLogin = false; 			 
			}else{
				isLogin = true; 
			}
		}  
		
	}else if(type&&type=='check'){ 
		if(!uid){ 
			uni.showToast({
				icon:'loading',
				title:'请先登录...',
				mask:true,
				duration:1000
			})
			uni.removeStorageSync('userInfo');
			uni.removeStorageSync('cookieKey');
			setTimeout(()=>{
				uni.navigateTo({
					url:'/pages/login/login?backType=prev'
				})
			},1000)
			isLogin = false;
		}else{ 
			let res=await api.user_api.checkLogin();   
			if(res.data.ret!=0){ 				 
				uni.showToast({
					icon:'loading',
					title:'登录已超时...',
					mask:true,
					duration:1000
				})
				uni.removeStorageSync('userInfo'); 
				uni.removeStorageSync('cookieKey');
				
				setTimeout(()=>{
					uni.navigateTo({
						url:'/pages/login/login?backType=prev'
					})
				},1000)
				isLogin = false; 			 
			}else{
				isLogin = true; 
			}
		}  
	}else{
		if(!uid){ 
			isLogin = false;
		}else{ 
			let res=await api.user_api.checkLogin(); 
			if(res.data.ret==0){ 				 
				isLogin = true;	 
			}else{
				isLogin = false; 
			}
		}  
		
	}
		
	return isLogin
}
 

export { 
	loginState
	
}